package com.yanqu.road.server.cmd.newmonopolymkt;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.newmonopolymkt.NewMonopolyMarketProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.newmonopolymkt.NewMonopolyMarketModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

import java.util.List;


@Cmd(code = GameProtocol.S_NEW_MONOPOLY_MARKET_NOTICE_BROADCAST_FROM_CROSS, desc = "下发公告广播 跨服返回区服 协议")
public class NewMonopolyMarketNoticeBroadcastFromCrossCmd implements Command {


    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        NewMonopolyMarketProto.NewBroadcastMonopolyMarketRespMsg noticeBroadcast = NewMonopolyMarketProto.NewBroadcastMonopolyMarketRespMsg.parseFrom(packet.getBytes());
        List<GamePlayer> onlinePlayer = GamePlayerMgr.getAllOnlinePlayer();
        for (GamePlayer player : onlinePlayer){
            NewMonopolyMarketModule monopolyMarketModule = player.getModule(NewMonopolyMarketModule.class);
            if(monopolyMarketModule.getInSystemId() == noticeBroadcast.getNewNotice().getType()){
                player.sendPacket(ClientProtocol.U_NEW_MONOPOLY_MARKET_BROADCAST, noticeBroadcast.toBuilder());
            }
        }
    }
}
